use TestHelper;
use ResourceManager;

printLog "=================================";
printLog "======= LOG MANAGER TEST ========";
printLog "=================================";

printLog "Obtaining ResourceManager: ". $rm;
my $rm = ResourceManager->new;
assertEq(ref $rm, "ResourceManager", "Type of resource manager must be ResourceManager");

printLog "Obtaining LogManager: ". $lm;
my $lm = $rm->getComponent("LogManager");
assertEq(ref $lm, "LogManager", "Type of log manager must be LogManager");

printLog "Marking start of the test in the logfile (may or may not work...)";
$lm->log("----------------------- TEST START ------------------------");

my $logmsg = "TEST1";
printLog "Testing automatic log start";
printLog "Logging ".$logmsg;
$lm->log($logmsg);

printLog "Closing";
$lm->end;

printLog "Testing logging to a closed log";
$logmsg = "TEST2";
printLog "Logging ".$logmsg;
$lm->log($logmsg);


printLog "Starting log again";
$lm->start;

$logmsg = "TEST3";
printLog "Logging ".$logmsg;
$lm->log($logmsg);

printLog "Marking end of the test in the logfile (may or may not work...)";
$lm->log("----------------------- TEST END --------------------------");

$lm->end;

printLog "Final status of the log file";
printLog "Only TEST1 and TEST3 expected at the end of the file";
printLog "";
open LOGFILE, "<".$lm->{LOGPATH};
while(<LOGFILE>){
    chomp;
    printLog($_);
}
close LOGFILE;



printAssertResults(); 

